package com.bookcode.dao;


import com.bookcode.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Column;
import java.util.List;
public interface StudentRepository extends JpaRepository<Student,Long> {
    /**
     * 根据学生id 来查找
     * */
//    @Query("select b from t_student b where b.Id=:Id")
//    List<Student> getStudentsById(@Param("Id") Long Id);
    /**
     *
     * */

    /**
     * 根据姓名查询学生
     */
    @Query("from Student s where s.name=:name")
    Student findStudentByName(@Param("name") String name);

    /**
    * 根据学生学号查查找学生
    * */
    @Query("select b from Student b where b.xuehao=:xuehao")
    Student getStudentByXuehao(@Param("xuehao") String xuehao);
    /**
     *
    * */
    /**
     * 根据学生学号查查找学生
     * */
    @Query("select b from Student b where b.username=:username")
    Student getStudentByUsename(@Param("username") String username);
    /**
     *删除该学号对应下的学生实体
     * */

    @Modifying
    @Query("delete from Student b where b.xuehao=:xuehao")
    void deleteStudentByXuehao(@Param("xuehao") String xuehao);

}